<template>
  <NuxtLayout name="admin" menuActive="/admin/student">
    <div class="card">
      <el-page-header @back="useRouter().go(-1)"></el-page-header>
      <div style="height: 18px;"></div>
      <el-table :data="tableData" border>
        <el-table-column prop="classes.name" label="班级名称" />
        <el-table-column prop="subject.name" label="科目名称" />
        <el-table-column prop="examSetting.passScore" label="及格分" />
        <el-table-column prop="examSetting.fullScore" label="总分" />
        <el-table-column prop="examSetting.duration" label="时长(秒)" />
        <el-table-column prop="examSecond" label="耗时(秒)" />
        <el-table-column label="状态">
          <template #default="scope">
            <el-tag type="success" v-show="scope.row.status == 1">合格</el-tag>
            <el-tag type="danger" v-show="scope.row.status == 0">不合格</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="score" label="得分" />
      </el-table>
      <div class="card_pagin">
        <el-pagination background layout="prev, pager, next, total" :total="total" :page-size="listForm.pageSize"
          @change="pageChangeFn" />
      </div>
    </div>
  </NuxtLayout>
</template>

<script setup>
import { userExamRecord } from '~/server/api'
// TDK
const prevHost = useRequestHeaders()["x-forwarded-proto"];
const host = useRequestHeaders()["host"];
const fullPath = useRoute()["fullPath"];
useSeoMeta({
  title: "技考邦_学员管理_考试记录",
  keywords: "技考邦,学员管理,考试记录",
  description: "技考邦，学员管理，考试记录。",
  ogTitle: "技考邦_学员管理_考试记录",
  ogDescription: "技考邦，学员管理，考试记录。",
  ogType: "article",
  ogUrl: `${prevHost}://${host}${fullPath}`,
});
// 列表
const listForm = ref({
  pageNum: 1,
  pageSize: 20,
  classesId: useRoute().params.classId,
  userId: useRoute().params.userId
})
const tableData = ref([])
const total = ref(0)
const getList = async () => {
  let { data: listRes } = await useAsyncData('userExamRecord', () => useServerRequest(userExamRecord, {
    method: 'post',
    body: JSON.stringify(listForm.value)
  }))
  if (listRes.value && listRes.value.errno === 0) {
    tableData.value = listRes.value.result.list;
    total.value = listRes.value.result.total;
  }
}
getList()
// 分页
const pageChangeFn = (val) => {
  listForm.value.pageNum = val;
  getList()
}
</script>

<style lang="less" scoped>
.card {
  background: #FFFFFF;
  border-radius: 10px;
  border: 1px solid #EEEEEE;
  padding: 35px 25px;

  &_pagin {
    margin-top: 30px;
    display: flex;
    justify-content: center;
  }
}
</style>